import os
import argparse
from pathlib import Path

parser = argparse.ArgumentParser("evaluation")

parser.add_argument('--eval-tpl', type=str, default='original sample', help="eval type list str")
parser.add_argument('--fold-list', type=str, help='eval fold list', default='1 2 3 4 5')
parser.add_argument('--debug', action='store_true')
parser.add_argument('--name', type=str, default='evaluation', help="log/pdf/fig save name")

group = parser.add_mutually_exclusive_group()    # 互斥组
group.add_argument('--root', type=str, help="root dir")
group.add_argument('--all', type=str, help='eval all')

args = parser.parse_args()
print(args)

def get_dir_lst(dir):
    """get dir lst

    :dir: TODO
    :returns: TODO

    """
    root = Path(dir)
    lst = list(map(lambda x: str(root.joinpath(x)), os.listdir(dir)))
    return lst


if __name__ == "__main__":
    project_dir = Path(__file__).resolve().parents[1]
    evalpy = project_dir.joinpath('evaluate_code/my_eval.py')

    if args.root is None:
        root_pth = Path(args.all)
        root_lst = get_dir_lst(f'{args.all}/canonical') + \
            get_dir_lst(f'{args.all}/aug') + get_dir_lst(f'{args.all}/transfer')
    else:
        root_lst = [args.root]
    for root in root_lst:
        cmd = (f'python {evalpy} '
               f'--root {root} '
               f'--eval-tpl {args.eval_tpl} '
               f'--fold-list {args.fold_list} '
               f'--name {args.name} ')
        if args.debug is True:
            cmd += f'--debug '
        else:
            cmd += '& '
        os.system(cmd)
